# -*- coding: utf-8 -*-
"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py

mx_set_eyelink_address = binder_py('mx_set_eyelink_address')
mx_set_eyelink_address.mx_c.headers = ['<eyelink.h>','"mex.h"']
mx_set_eyelink_address.mx_c.code = '''

INT16 _main( char *ops )
{
    return set_eyelink_address( ops );
}


void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    char *mb;
    double *status;
    mwSize td[] = {1,1};
    /* Verify input arguments. */
    if(nrhs != 1 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 1 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
    
    if ( mxIsChar(*prhs) != 1 )
      mexErrMsgTxt( "name must be a string." );
      
    mb  = mxArrayToString(*prhs);
    
    if(mb == NULL) 
      mexErrMsgTxt("Could not convert input to string.");
    
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status  = mxGetPr(plhs[0]);    
    *status = (double ) _main( mb );    
    mxFree( mb );
    return;
}


'''

mx_set_eyelink_address.mx_c.mdoc = \
'''function [ status ] = mx_set_eyelink_address( )
%MX_SET_EYELINK_ADDRESS Sets the IP address used for connection to the EyeLink 
% tracker. This is set to "100.1.1.1" in the DLL, but may need to be changed 
% for some network configurations. This must be set before attempting to open 
% a connection to the tracker.
%
% Remarks:
% A "broadcast" address ("255.255.255.255") may be used if the tracker address 
% is not known - this will work only if a single Ethernet card is installed, 
% or if DLL version 2.1 or higher, and the latest tracker software versions 
% (EyeLink I v2.1 or higher, and EyeLink II v1.1 or higher) are installed.
% Parameters:
% addr 	Pointer to a string containing a "dotted" 4-digit IP address.
% Returns:
% 0 if success, -1 if could not parse address string.
%
'''
mx_set_eyelink_address.write_c()
mx_set_eyelink_address.write_m()
mx_set_eyelink_address.compile()
mx_set_eyelink_address.write_sh()

